#pragma once

#include "Animation.h"
#include "InputEvent.h"
#include "ExtraPtsText.h"

// image
#define CH_PATH "CircusCharlieSheet1.png"
#define CH_SRC_X 164
#define CH_SRC_Y 58
#define CH_SRC_W 16
#define CH_SRC_H 24

// sprite position and size
#define CH_FIXED_X 150
#define CH_START_Y 200
#define CH_WIDTH 48
#define CH_HEIGHT 72

// general animation settings
#define CH_ANIM_FPS 8
#define CH_ANIM_LOOP true
#define CH_ANIM_HORZ true

// walk right animation atlas
#define WR_SRC_X 164
#define WR_SRC_Y 5
#define WR_SRC_W 16
#define WR_SRC_H 24
#define WR_SRC_OFFSET 5
#define WR_FRAMES 3

// walk left animation atlas
#define WL_SRC_X 97
#define WL_SRC_Y 5
#define WL_SRC_W 16
#define WL_SRC_H 24
#define WL_SRC_OFFSET 5
#define WL_FRAMES 3

// jump right animation atlas
#define JR_SRC_X 226
#define JR_SRC_Y 5
#define JR_SRC_W 16
#define JR_SRC_H 24
#define JR_SRC_OFFSET 5
#define JR_FRAMES 1

// jump left animation atlas
#define JL_SRC_X 76
#define JL_SRC_Y 5
#define JL_SRC_W 16
#define JL_SRC_H 24
#define JL_SRC_OFFSET 5
#define JL_FRAMES 1

// finish animation atlas
#define FH_SRC_X 83
#define FH_SRC_Y 58
#define FH_SRC_W 16
#define FH_SRC_H 24
#define FH_SRC_OFFSET 2
#define FH_FRAMES 2

// movement
#define CH_ACCELERATION 1200.0f
#define CH_MAX_SPEED 300.0f
#define CH_JUMP_SPEED 800.0f
#define CH_GRAVITY_Y_EFFECT 1500.0f
#define CH_RIGHT_KEY InputEvent::KEY_RIGHT
#define CH_LEFT_KEY InputEvent::KEY_LEFT
#define CH_JUMP_KEY InputEvent::KEY_UP

class Circus;

class Charlie: public Sprite {
private: 
	bool isTouchingTheGround;
	bool hasFinished;
	bool addBonusText;
	int jumpPts;
	Vector *mvt;
	Circus *game;
	Animation *walkLeft;
	Animation *walkRight;
	Animation *jumpLeft;
	Animation *jumpRight;
	Animation *finish;
	Animation *current;
	ExtraPtsText *extraPtsText;
	void AdjustMvtToInput(float);
	void AdjustMvtToGravity(float);
	void PointsForJump();
	void MoveOnInput(float);
	void JumpOnInput();
	void AdjustToMaxSpeed();
	void Move(float);
	void CheckCollisions();
	void CheckFinish(float);
	void ShowAnimation();
	void Die();
public:
	Charlie();
	Charlie(Circus*);
	virtual ~Charlie();
	void Update(float);
	void ResetPos();
	bool GetFinished(){ return hasFinished; }
	void ResetCharlie();
	bool IsTouchingTheGround() { return isTouchingTheGround; }
};